/**
 * 
 */
package no.ntnu.fp.testing;

import static org.junit.Assert.*;

import java.util.ArrayList;

import no.ntnu.fp.model.FactoryProject;
import no.ntnu.fp.model.SimpleEcu;
import no.ntnu.fp.model.Software;
import no.ntnu.fp.model.Vehicle;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author Morten
 *
 */
public class FactoryProjectTest {

	/**
	 * @throws java.lang.Exception
	 */
	
	FactoryProject f;
	java.util.ArrayList vehicleList; 
	java.util.ArrayList softwareList; 
	java.util.ArrayList<SimpleEcu> ecuList;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		f = new FactoryProject();
		assertTrue(f instanceof FactoryProject);
		vehicleList = new java.util.ArrayList();
		softwareList = new java.util.ArrayList();
		ecuList = new java.util.ArrayList<SimpleEcu>();
		
		vehicleList.add(new Vehicle());
		softwareList.add(new Software());
		ecuList.add(new SimpleEcu());
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#FactoryProject()}.
	 */
	@Test
	public void testFactoryProject() {
		f = new FactoryProject();
		assertTrue(f instanceof FactoryProject);
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#FactoryProject(java.util.ArrayList, java.util.ArrayList, java.util.ArrayList)}.
	 */
	@Test
	public void testFactoryProjectArrayListArrayListArrayListOfSimpleEcu() {
		f = new FactoryProject(vehicleList, softwareList, ecuList);
		assertTrue(f instanceof FactoryProject);
		
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getVehicleCount()}.
	 */
	@Test
	/**
	 * One line methods like getter and setter do not need testing
	 */
	public void testGetVehicleCount() {
		f = new FactoryProject();
		assertEquals(0, f.getVehicleCount());
		f.addVehicle(new Vehicle());
		assertEquals(1, f.getVehicleCount());
		f.removeVehicle(f.getLatestVehicle());
		assertEquals(0, f.getVehicleCount());
		
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getSoftwareCount()}.
	 */
	@Test
	public void testGetSoftwareCount() {
		f = new FactoryProject();
		assertTrue(f.getSoftwareCount()==0);
		Software s = new Software(1, 1, "asd");
		f.addSoftware(s);
		assertTrue(f.getSoftwareCount()==1);
		f.addSoftware(s);
		assertTrue(f.getSoftwareCount()==2);
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getVehicle(int)}.
	 */
	@Test
	public void testGetVehicle() {
		f = new FactoryProject();
		Vehicle v = new Vehicle("asd", null, null, null);
		f.getVehicle(0);
		
		f.addVehicle(v);
		assertEquals(v, f.getVehicle(0));
		Vehicle v2 = new Vehicle("asd", null, null, null);
		f.addVehicle(v2);
		assertEquals(v2, f.getVehicle(1));
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getSoftware(int)}.
	 */
	@Test
	public void testGetSoftware() {
		f = new FactoryProject();
		Software s = new Software(1, 1, "asd");
		Software s0 = f.getSoftware(f.getSoftwareIndex(s));
		f.addSoftware(s);
		
		Software so = f.getSoftware(f.getSoftwareIndex(s));
		assertEquals(so, s);
		assertEquals(1, so.getSwVersion());
		assertEquals(1, so.getSubVersion());
		assertEquals("asd", so.getUrl());
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getEcuCount()}.
	 */
	@Test
	public void testGetEcuCount() {
		f = new FactoryProject();
		SimpleEcu se = new SimpleEcu(1);
		f.addEcu(se);
		assertTrue(f.getEcuCount()==1);
		
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getLatestSoftware()}.
	 */
	@Test
	public void testGetLatestSoftware() {
		f = new FactoryProject();
		Software s = new Software(1, 1, "asd");
		
		Software s0 = f.getLatestSoftware();
		
		f.addSoftware(s);
		
		Software so = f.getLatestSoftware();
		assertEquals(so, s);
		assertEquals(1, so.getSwVersion());
		assertEquals(1, so.getSubVersion());
		assertEquals("asd", so.getUrl());
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getLatestVehicle()}.
	 */
	@Test
	public void testGetLatestVehicle() {
		f = new FactoryProject();
		Vehicle v = new Vehicle();
		Vehicle v0 = f.getLatestVehicle();
		
		f.addVehicle(v);
		Vehicle ve = f.getLatestVehicle();
		assertEquals(v, ve);

	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getLatestEcu()}.
	 */
	@Test
	public void testGetLatestEcu() {
		f = new FactoryProject();
		SimpleEcu s0 = f.getLatestEcu();
		SimpleEcu se = new SimpleEcu(1);
		f.addEcu(se);
		assertTrue(f.getEcuCount()==1);
		assertEquals(se, f.getLatestEcu());
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getSoftwareIndex(no.ntnu.fp.model.Software)}.
	 */
	@Test
	public void testGetSoftwareIndex() {
		f = new FactoryProject();
		Software s = new Software(1, 1, "asd");
		assertEquals(-1, f.getSoftwareIndex(s));
		f.addSoftware(s);
		assertEquals(0, f.getSoftwareIndex(s));
		Software s2 = new Software(2, 1, "asd2");
		f.addSoftware(s2);
		assertEquals(1, f.getSoftwareIndex(s2));
		

	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getEcu(int)}.
	 */
	@Test
	public void testGetEcu() {
		f = new FactoryProject();

		SimpleEcu s = new SimpleEcu();
		SimpleEcu s0 = f.getEcu(0);
		f.addEcu(s);
		assertEquals(s, f.getEcu(0));
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#getVehicleIndex(java.lang.String)}.
	 */
	@Test
	public void testGetVehicleIndex() {
		f = new FactoryProject();
		Vehicle v = new Vehicle("asd", null, null, null);
		f.addVehicle(v);
		assertEquals(0, f.getVehicleIndex("asd"));
		assertEquals(-1, f.getVehicleIndex("asd2"));

	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#indexOf(java.lang.Object)}.
	 */
	
	@Test
	public void testIndexOf() {
		f = new FactoryProject();
		Vehicle v = new Vehicle();
		f.addVehicle(v);
		assertEquals(0, f.indexOf(v));
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#iterator()}.
	 */


	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#addVehicle(no.ntnu.fp.model.Vehicle)}.
	 */
	@Test
	public void testAddVehicle() {
		f = new FactoryProject();
		Vehicle v = new Vehicle("asd", null, null, null);
		f.addVehicle(v);
		assertEquals(v, f.getVehicle(0));
		f.removeVehicle(v);
		assertEquals(-1, f.getVehicleIndex("asd"));
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#addSoftware(no.ntnu.fp.model.Software)}.
	 */
	@Test
	public void testAddSoftware() {
		f = new FactoryProject();
		Software s = new Software(1, 1, "asd");
		f.addSoftware(s);
		
		Software so = f.getSoftware(f.getSoftwareIndex(s));
		assertEquals(1, so.getSwVersion());
		assertEquals(1, so.getSubVersion());
		assertEquals("asd", so.getUrl());
		
		Software s2 = new Software(1, 1, "asd");
		assertEquals(-1, f.getSoftwareIndex(s2));
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#addEcu(no.ntnu.fp.model.SimpleEcu)}.
	 */
	@Test
	public void testAddEcu() {
		f = new FactoryProject();
		SimpleEcu se = new SimpleEcu(1);
		f.addEcu(se);
		assertTrue(f.getEcuCount()==1);
		assertEquals(se, f.getEcu(0));
		
	}

	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#removeVehicle(no.ntnu.fp.model.Vehicle)}.
	 */
	@Test
	public void testRemoveVehicle() throws Exception {
		f = new FactoryProject();
		assertEquals(0, f.getVehicleCount());
		Vehicle v = new Vehicle();
		f.addVehicle(v);
		assertEquals(v, f.getVehicle(0));
		f.removeVehicle(v);
		assertEquals(0, f.getVehicle(0));
		f.removeVehicle(v);
	}






	/**
	 * Test method for {@link no.ntnu.fp.model.FactoryProject#equals(java.lang.Object)}.
	 */
	@Test
	public void testEqualsObject() {
		f = new FactoryProject(vehicleList, softwareList, ecuList);
		
		assertTrue(f.equals(f));
	}



}
